package edu.joe.game.solvers;

import edu.joe.game.ParticleData;
import edu.joe.game.ParticleMotionSolver;
import edu.joe.game.ParticlePhysicsModel;

/**
 * Phantom solver is the simplest physics solver. It does not collide particles,
 * and updates x,y,z positions by dx,dy,dz, and updates fx,fy,fz with their
 * damping forces. It has the highest performance because the update loop is
 * merely O(n) time.
 * 
 * @author Joe
 * 
 */
public class PhantomSolver extends ParticleMotionSolver {

	public PhantomSolver(ParticleData[] particles, ParticlePhysicsModel physics) {
		super(particles, physics);
	}

	@Override
	public void update(double dt) {
		for (int i = 0; i < super.particles.length; i++) {
			ParticleData particle = super.particles[i];
			if (particle.life > 0) {
				particle.life -= dt;
				particle.x += particle.dx * dt;
				particle.y += particle.dy * dt;
				particle.z += particle.dz * dt;

				particle.dx *= this.physics.velocityDamp;
				particle.dy *= this.physics.velocityDamp;
				particle.dz *= this.physics.velocityDamp;

				particle.dx += particle.fx;
				particle.dy += particle.fy + this.physics.gravity*dt;
				particle.dz += particle.fz;

				particle.fx *= this.physics.velocityDamp;
				particle.fy *= this.physics.velocityDamp;
				particle.fz *= this.physics.velocityDamp;
				if (physics.hitsFloor && particle.y < 0) {
					particle.dy *= -physics.bounceFactor;
					particle.y = 0.1;
				}
			}
		}
	}
}
